<?php

/*
 * This class is used for as Model for Product table 
 */

class Model_Propertykmlcoordinates extends Model_Base {

    protected $_name = 'property_kml_coordinate';
    protected $_primaryKey = 'prpkc_id';

    public function fetchEntryById($id) {
        $select = $this->select()
                ->from(array('lgn' => 'property_kml_coordinate'))
                ->where('prpkc_id = ?', $id);
        // see reasoning in fetchEntries() as to why we return only an array
        $data = $this->fetchRow($select);
        if (!empty($data)) {
            return $data->toArray();
        } else {
            return array();
        }
    }

    /**
     *  This function is used to get Questions
     * @return null|Zend_Db_Table_Row_Abstract
     */
    public function fetchPropertyKmlCoordinates($where = "", $limit = "", $offset = "0", $order = 'prpkc_id', $sort = 'ASC') {
        $select = $this->select()
                ->from(array('prtyp' => 'property_kml_coordinate'));
        if ($where != '') {
            $select->where($where);
        }
        if ($limit != "") {
            $select->limit($limit, $offset);
        }
        $select->order($order . " " . $sort);
        $data = parent::fetchAll($select);
        if (!empty($data)) {
            return $data->toArray();
        } else {
            return array();
        }
    }

    public function fetchPropertyKmlCoordinatesByPrpId($id = "") {
        if ($id == "") {
            return array();
        }
        $select = $this->select()
                ->from(array('prtyp' => 'property_kml_coordinate'));
                $select->where("prp_id = '".$id."'");
        $select->order("prpkc_id ASC");
        $data = parent::fetchAll($select);
        if (!empty($data)) {
            
            $finalArray = Array();
            $i = 0;
            foreach ($data->toArray() as $_kvalue) {
                $finalArray[$i]['lat'] = $_kvalue['prpkc_lat'];
                $finalArray[$i]['lon'] = $_kvalue['prpkc_lon'];
                $i++;
            }
            return $finalArray;
        } else {
            return array();
        }
    }

}
